package com.atguigu.rabbitmq.springbootmq.consumer;

import cn.hutool.Hutool;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.atguigu.rabbitmq.springbootmq.config.DelayedQueueConfig;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @description: TODO 消费者代码
 * @author zhangbanglong
 * @date 2024/1/13 12:48
 * @version 1.0
 */
@Slf4j
@Component
public class DeadLetterQueueConsumer {


    
    /**  
     * @description: 消费者 监听 QD
     * @param: null  
     * @return:   
     * @author zhangbanglong
     * @date: 2024/1/13 12:51
     */ 
    @RabbitListener(queues = "QD")
    public void receiveD(Message message, Channel channel){
        String msg=new String(message.getBody());

        log.info("当前时间：{},收到死信队列信息{}", DateUtil.format(new Date(), DatePattern.NORM_DATETIME_FORMATTER),msg);

    }

    @RabbitListener(queues = DelayedQueueConfig.QUEUE_NM)
    public void receiveDelayedQueue(Message message){
        String msg=new String(message.getBody());
        log.info("当前时间：{},收到延时队列信息{}", DateUtil.format(new Date(), DatePattern.NORM_DATETIME_FORMATTER),msg);
    }
}
